package com.freesun.monitor.ld;

import com.freesun.monitor.db.OperateMariaDb;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;

/**
 * Created by yangfei on 13-12-6.
 * loadrunner 性能测试
 */
public class OneDbSelectMonitor {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    private OperateMariaDb operateMariaDb;
    String st = "select * from test01 order by created_at desc";


    /**
     * @desc 初始化连接数据库
     * @return
     * @throws Throwable
     */
    public int init() throws Throwable{
        operateMariaDb = new OperateMariaDb();
        operateMariaDb.GetConnect("jdbc:mysql://192.168.1.67:3306/onedb", "root", "123456");
        return 0;
    }

    /**
     * @desc 可以执行多次，可以进行参数操作
     * @return
     * @throws Throwable
     */
    public int action() throws Throwable{
        ResultSet rs = operateMariaDb.SelectData(st);
        log.debug("编号" + "\t" + "姓名" + "\t" + "密码" + "\t" + "备注" + "\t" + "创建时间" + "\t" + "修改时间");
        while (rs.next()){
            log.debug(rs.getInt(1) +rs.getString(2) +rs.getString(3) +rs.getString(4) +rs.getTimestamp(5) +rs.getTimestamp(6));
        }
        rs.close();
        return 0;
    }

    /**
     * @desc 销毁数据只执行一次
     * @return
     * @throws Throwable
     */
    public int end() throws Throwable{
        operateMariaDb.ConnectClose();
        return 0;
    }
}
